﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TagPropagator;
using System.Xml.Serialization;
using System.IO;
using System.Drawing;
using TagPropagator.Enums;
namespace TestApp
{
    class Program
    {

        static void Test1()
        {
            GraphBuilder builder = new GraphBuilder(new Graph(), new Comparer(), new FeatureExtractor(),
                new DFSAgent(), new PurgeAgent(), new Serializer());
            String path = "C:\\Users\\bartek\\Pictures\\Tapety\\grapf.xml";
            String pics = "C:\\Users\\bartek\\Pictures\\Tapety";
            foreach (var file in Directory.GetFiles(pics))
            {
                if (!file.Contains(".jpg")) continue;
                Node node = new Node();
                node.Image = file;

                //Dodawanie tagow: stub
                int howMany = new Random().Next(10);
                for (int i = 0; i < howMany; i++)
                {
                    node.Tags.Add("tag" + i, new Random().NextDouble());
                }

                builder.AddNode(node);
            }

            Console.WriteLine("Budowanie grafu done");
            builder.Purge(0.3);
            Console.WriteLine("Czyszczenie grafu done...");
            builder.PropagateKnowledge(10000);
            Console.WriteLine("DFS done...");
            builder.PropagationAgent = new BFSAgent();
            builder.PropagateKnowledge(10000);
            Console.WriteLine("BFS done");
            builder.PropagationAgent = new RandomAgent();
            builder.PropagateKnowledge(100000);
            Console.WriteLine("Random done...");
            builder.Save("C:\\asd.xml");
            builder.Load("C:\\asd.xml");
            Console.ReadKey();
        }

        static void Test2()
        {
            GraphBuilder builder = new GraphBuilder(new Graph(), new Comparer(), new FeatureExtractor(),
                new DFSAgent(), new PurgeAgent(), new Serializer());

            String plik = "C:\\5kzdjecBezSasiadow.xml";
            Serializer ser = new Serializer();
            Graph g = ser.Deserialize(plik);
            builder.AddNodes(g);
            builder.Save("C:\\5kzdjecFULL2.xml");
        }

        static void Main(string[] args)
        {
            //Test1();
            Test2();
            //Test3();
            //Test4(new DFSAgent());
            //Test4(new BFSAgent());
            //Test4(new RandomAgent());
        }

        private static void Test4(IPropagationAgent p)
        {
            GraphBuilder builder = new GraphBuilder(new Graph(), new Comparer(), new FeatureExtractor(),
               new DFSAgent(), new PurgeAgent(), new Serializer());
            builder.Load("C:\\5kzdjecWyczyszczony0,8.xml");
            builder.PropagationAgent = p;
            builder.PropagateKnowledge(100);
            Console.WriteLine("Propagation complete");
            builder.Save("C:\\Obliczenia08" + p.ToString() + ".xml");
        }

        private static void Test3()
        {
            GraphBuilder builder = new GraphBuilder(new Graph(), new Comparer(), new FeatureExtractor(),
               new DFSAgent(), new PurgeAgent(), new Serializer());
            builder.Load("C:\\5kzdjecFULL.xml");
            Console.WriteLine("Budowanie grafu done");
            builder.Purge(0.6);
            Console.WriteLine("Czyszczenie grafu done...");
            builder.Save("C:\\5kzdjecWyczyszczony" + 0.6 + ".xml");

            builder.Purge(0.7);
            builder.Save("C:\\5kzdjecWyczyszczony" + 0.7 + ".xml");

            builder.Purge(0.8);
            builder.Save("C:\\5kzdjecWyczyszczony" + 0.8 + ".xml");
        }
    }
}
